//
//  HYHomeFolderCollectionCell.m
//  XPlayer
//
//  Created by liguoqing on 2023/9/5.
//

#import "HYHomeFolderCollectionCell.h"
#import "HYHomeFileItemViewModel.h"
#import <HYUtls/CommUtls+Time.h>

@implementation HYHomeFolderCollectionCell

- (void)configUI
{
    [super configUI];
    [self.backView addSubview:self.iconView];
    [self.backView addSubview:self.descLabel];
    [self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.backView).offset(kItemSpace+2);
        make.left.equalTo(self.backView).offset(kItemSpace+2);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(20);
    }];
    [self addLongPressGesture];
}

- (void)bindViewModel:(HYHomeFileItemViewModel *)vm
{
    [super bindViewModel:vm];
    if(vm.isLock){
        self.iconView.image = [UIImage imageNamed:@"icon_lock_mode"];
    }
    if(vm.fileType == HYHomeFileType_Folder){
        self.coverView.image = [UIImage imageNamed:@"grid_folder_mode"];
    }else if(vm.fileType == HYHomeFileType_Audio){
        self.coverView.image = [UIImage imageNamed:@"icon_file_music"];
    }else if(vm.fileType == HYHomeFileType_Pic){
        self.coverView.image = [UIImage imageWithContentsOfFile:vm.filePath];
    }else if (vm.fileType == HYHomeFileType_File){
        self.coverView.image = [UIImage imageNamed:@"icon_file_text"];
    }else if (vm.fileType == HYHomeFileType_Zip){
        self.coverView.image = [UIImage imageNamed:@"icon_file_zip"];
    }else if (vm.fileType == HYHomeFileType_Other){
        self.coverView.image = [UIImage imageNamed:@"icon_file_other"];
    }
    self.descLabel.hidden = NO;
    if(vm.fileSize){
        self.descLabel.text = [CommUtls getSize:@(vm.fileSize)];
    }else if(vm.videoDuration){
        self.descLabel.text = vm.videoDuration;
    }else{
        self.descLabel.hidden = YES;
    }
}

@end
